using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace XNAPlatformer.Source.Weapons
{
    public class Bullet
    {
        private PlayerIndex owner;
        private Vector2 position;
        private Texture2D texture;
        private float velocity;
        private Vector2 direction;
        private bool isDead;
        private Color[] colors;

        #region Accessors

        public bool IsDead
        {
            get
            {
                return isDead;
            }
            set
            {
                isDead = value;
            }
        }

        public Color[] Colors
        {
            get
            {
                return colors;
            }
        }

        
        #endregion

        public Bullet(Vector2 position, Vector2 direction, Texture2D texture, float velocity)
        {
            this.position = position;
            this.direction = new Vector2(direction.X, direction.Y * -1);
            this.direction.Normalize();
            this.texture = texture;
            this.velocity = velocity;
            colors = new Color[texture.Width * texture.Height];
            texture.GetData(colors);
        }

        public void Update(GameTime gameTime)
        {
            position += direction * velocity;

            if (position.Y < -10 ||
                position.Y > 490 ||
                position.X < -10 ||
                position.X > 650)
            {
                isDead = true;
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spritebatch)
        {
            spritebatch.Draw(texture, position, Color.White);
        }

        public Rectangle BoundingRectangle()
        {
            return (new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height)); 
        }
    }
}
